<template>
  <q-page class="cc-admin">

    <div class="col bg-white shadow-2 q-pa-md q-ma-sm">
      <q-table flat color="primary" class="cross_table" separator="cell" :columns="columns" :data="list" row-key="id"
        :pagination.sync="pagination" :visible-columns="group" @request="query"
        :rows-per-page-options="[10, 20, 50, 100]" selection="multiple" :selected.sync="selected">

        <template v-slot:top="">
          <div class="row no-wrap full-width">
            <!-- <q-input clearable outlined dense placeholder="请输入关键字搜索" class="on-left" @input="query" debounce="500"
              v-model="key">
              <template #append>
                <q-btn flat round icon="search" color="primary" @click="query" :loading="loading">
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input> -->
            <q-space />
            <!-- <table-top-btns label="台风预警级别" modelName="warningLevel" :showAdd="true" :table="table" :selected="selected"
              :importing="importing" :exporting="exporting" :importExcelUrlFull="importExcelUrlFull" :columns="columns"
              @groupChange="groupChange" @add="add" @importExcel="importExcel" @exportExcel="exportExcel"
              @showConfirm="showConfirm" /> -->
              <div class="q-gutter-xs">
              <q-btn icon="add" no-wrap color="primary" label="新建" @click="add" />

            </div>
          </div>
        </template>
        <template #body-cell-opt="props">
          <q-td :props="props" :auto-width="true">
            <q-btn flat round dense color="primary" icon="edit" @click="edit(props.row)">
              <q-tooltip>编辑</q-tooltip></q-btn>
            <!-- <q-btn flat round dense color="primary" icon="mdi-content-copy" @click="copy(props.row)">
              <q-tooltip>复制</q-tooltip>
            </q-btn> -->
            <btn-del label="台风预警级别" @confirm="del(props.row)" />
          </q-td>
        </template>
      </q-table>
    </div>
    <q-dialog maximized flat persistent ref="dialog">
      <q-form @submit="submit" class="dialog_card column">
        <h5 class="view_title justify-between q-px-md">
          {{ editType }}
          <q-btn dense outline round icon="clear" size="sm" v-close-popup />
        </h5>
        <q-scroll-area class="col">
          <div class="row q-col-gutter-x-md dialog_form q-pa-md">
            <div class="dynamic-form-item ">
              <div v-show="true" class="dynamic-form-item-label" style="width:100%;">
                <q-icon name="star" color="red" v-show="true" />
                预警级别：
              </div>
              <q-input v-if="!editableForm[101]" v-model="form.warningLevel"
                class="readonly dense hide-bottom-space outlined " />
              <select-search dense debounce="500" hide-bottom-space outlined :options="warning_level"
                v-model="form.warningLevel" type="select" @input="uploadDesc" />
            </div>
          </div>
          <div class="col-12 dynamic-form-item-label q-pa-md " style="width:100%; padding-left: 20px; padding-right: 20px;">
            预警描述：
            <q-input outlined  dense v-model="form.warningDescription" type="textarea" />
          </div>
        </q-scroll-area>
        <div class="row justify-center q-pa-md">
          <q-btn outline color="primary" icon="mdi-close-thick" label="关闭" v-close-popup />
          <q-btn class="q-mx-md" color="primary" icon="mdi-check-bold" label="提交" :loading="loading" type="submit" />
        </div>
      </q-form>
    </q-dialog>
    <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
    <q-inner-loading :showing="loading">
      <q-spinner-gears size="50px" color="primary" />
    </q-inner-loading>
  </q-page>
</template>

<script>
import { IndexMixin } from 'boot/mixins';
import { getDictLabel } from 'boot/dictionary';
import confirm from 'components/confirm';

export default {
  name: 'TyphoonWarningLevel',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      form: {
        id: null,
        warningLevel: '',
        warningDescription: ''
      },
      editableForm: {
        101: true,

      },
      index: 0,
      warning_level: ['蓝色预警', '黄色预警', '橙色预警', '红色预警'],
      warning_description: ['预计未来 72 小时内将受到台风影响，平均风力达 6 级以上，或者阵风 8 级以上。',
        '预计未来 48 小时内将受到台风影响，平均风力达 8 级以上，或者阵风 10 级以上。',
        '预计未来 24 小时内将受到台风影响，平均风力达 10 级以上，或者阵风 12 级以上。',
        '预计未来 12 小时内将受到台风影响，平均风力达 12 级以上，或者已达 12 级以上并可能持续。'
      ],
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
        },
        {
          name: 'warningLevel', align: 'center', label: '预警级别', field: 'warningLevel',
        },
        {
          name: 'warningDescription', align: 'center', label: '预警描述', field: 'warningDescription',
        },
        {
          name: 'opt', align: 'center', label: '操作', field: 'id',
        },
      ],
      showQuery: true,
      headers: [{ name: 'Authorization', value: localStorage.Authorization }],
      uploadUrl: `${process.env.SERVER_URL}${process.env.BASE_URL}/sys/common/upload`,
      imgUrl: `${process.env.SERVER_URL}${process.env.BASE_URL}/sys/common/static`,
      url: {
        list: '/typhoon/warningLevel/list',
        add: '/typhoon/warningLevel/add',
        edit: '/typhoon/warningLevel/edit',
        copy:
          '/typhoon/warningLevel/copy',
        delete: '/typhoon/warningLevel/delete',
        deleteBatch: '/typhoon/warningLevel/deleteBatch',
        exportXlsUrl: '/typhoon/warningLevel/exportXls',
        importExcelUrl: '/typhoon/warningLevel/importExcel',
      },
    };
  },
  methods: {
    uploadDesc() {
      const index = this.warning_level.indexOf(this.form.warningLevel);
      const describe = this.warning_description[index];
      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
      this.form.warningDescription = describe;
      console.log(this.form.warningDescription);
    },
    getDictLabel,
    initDict() {
    },
  },
  mounted() {
    this.initDict();
  },
  computed: {

  },
};
</script>

<style lang="stylus">

</style>
